package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.UserCredit;
import cn.wolfcode.trip.base.mapper.UserCreditMapper;
import cn.wolfcode.trip.base.service.IUserCreditService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserCreditServiceImpl implements IUserCreditService {

    @Autowired
    private UserCreditMapper userCreditMapper;


    @Override
    public void save(UserCredit userCredit) {
        userCreditMapper.insert(userCredit);
    }

    @Override
    public void delete(Long id) {
        userCreditMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<UserCredit> selectAll() {
        return userCreditMapper.selectAll();
    }

    @Override
    public void update(UserCredit userCredit) {
        userCreditMapper.updateByPrimaryKey(userCredit);
    }

    @Override
    public UserCredit get(Long id) {
        return userCreditMapper.selectByPrimaryKey(id);
    }

    @Override
    public UserCredit getCreditsByUserId(Long userId) {
        return userCreditMapper.selectByUserId(userId);
    }

    @Override
    public void decreaseCreditByUserId(Long userId, int price) {
        userCreditMapper.decreaseCreditByUserId(userId,price);
    }

}
